﻿<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="using:Microsoft.PlayerFramework"
  >

    <ResourceDictionary.ThemeDictionaries>
        <ResourceDictionary x:Key="Default">
            <SolidColorBrush x:Key="TransportBackgroundBrush" Color="#44000000"/>
            <SolidColorBrush x:Key="TransportReversedBackgroundBrush" Color="#BBFFFFFF"/>
        </ResourceDictionary>
        <ResourceDictionary x:Key="Light">
            <SolidColorBrush x:Key="TransportBackgroundBrush" Color="#BBFFFFFF"/>
            <SolidColorBrush x:Key="TransportReversedBackgroundBrush" Color="#44000000"/>
        </ResourceDictionary>
    </ResourceDictionary.ThemeDictionaries>

    <ControlTemplate x:Key="SeekableSliderTemplate" TargetType="local:SeekableSlider">
        <Grid x:Name="LayoutRoot">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal"/>
                    <VisualState x:Name="Pressed">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalDecreaseRect" Storyboard.TargetProperty="Fill">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonPressedForegroundThemeBrush}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalTrackRect" Storyboard.TargetProperty="Fill">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SliderTrackPressedBackground, RelativeSource={RelativeSource TemplatedParent}}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalThumb" Storyboard.TargetProperty="Background">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SliderThumbPressedBackground, RelativeSource={RelativeSource TemplatedParent}}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalThumb" Storyboard.TargetProperty="BorderBrush">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SliderThumbPressedBorder, RelativeSource={RelativeSource TemplatedParent}}" />
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Disabled">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalBorder" Storyboard.TargetProperty="Stroke">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SliderDisabledBorder, RelativeSource={RelativeSource TemplatedParent}}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalDecreaseRect" Storyboard.TargetProperty="Fill">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SliderTrackDecreaseDisabledBackground, RelativeSource={RelativeSource TemplatedParent}}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalTrackRect" Storyboard.TargetProperty="Fill">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SliderTrackDisabledBackground, RelativeSource={RelativeSource TemplatedParent}}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalThumb" Storyboard.TargetProperty="Background">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SliderThumbDisabledBackground, RelativeSource={RelativeSource TemplatedParent}}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalThumb" Storyboard.TargetProperty="BorderBrush">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SliderThumbDisabledBackground, RelativeSource={RelativeSource TemplatedParent}}" />
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="PointerOver">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalDecreaseRect" Storyboard.TargetProperty="Fill">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource ButtonPointerOverForegroundThemeBrush}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalTrackRect" Storyboard.TargetProperty="Fill">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SliderTrackPointerOverBackground, RelativeSource={RelativeSource TemplatedParent}}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalThumb" Storyboard.TargetProperty="Background">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SliderThumbPointerOverBackground, RelativeSource={RelativeSource TemplatedParent}}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HorizontalThumb" Storyboard.TargetProperty="BorderBrush">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding SliderThumbPointerOverBorder, RelativeSource={RelativeSource TemplatedParent}}" />
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="FocusStates">
                    <VisualState x:Name="Focused">
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="FocusVisualWhite" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
                            <DoubleAnimation Storyboard.TargetName="FocusVisualBlack" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Unfocused" />
                    <VisualState x:Name="PointerFocused" />
                </VisualStateGroup>
                <VisualStateGroup x:Name="ScrubbingStates">
                    <VisualState x:Name="NotScrubbing" />
                    <VisualState x:Name="Scrubbing" />
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>

            <Grid x:Name="HorizontalTemplate">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <ContentPresenter x:Name="HorizontalBackgroundContentPresenter" Margin="{TemplateBinding Padding}" Content="{TemplateBinding HorizontalBackgroundContent}" Grid.ColumnSpan="3" Grid.RowSpan="3"/>
                <Rectangle x:Name="HorizontalTrackRect" Margin="{TemplateBinding Padding}" Grid.Row="1" Fill="{TemplateBinding Background}" Grid.Column="0" Grid.ColumnSpan="3" IsHitTestVisible="False" />
                <Rectangle x:Name="HorizontalDecreaseRect" Margin="{TemplateBinding Padding}" Grid.Row="1" Fill="{ThemeResource ButtonForegroundThemeBrush}" Grid.Column="0" IsHitTestVisible="False"/>
                <Rectangle x:Name="HorizontalBorder" Margin="{TemplateBinding Padding}" Grid.Row="1" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="3" IsHitTestVisible="False" />
                <Border x:Name="HorizontalAvailableBar" Grid.RowSpan="3" Grid.ColumnSpan="3" HorizontalAlignment="Left" IsHitTestVisible="True" Background="#00000000" />
                <ContentPresenter x:Name="HorizontalForegroundContentPresenter" Margin="{TemplateBinding Padding}" Content="{TemplateBinding HorizontalForegroundContent}" Grid.ColumnSpan="3" Grid.RowSpan="3"/>
                <Thumb x:Name="HorizontalThumb" Background="{TemplateBinding SliderThumbBackground}" DataContext="{TemplateBinding Value}" Grid.RowSpan="3" Grid.Column="1">
                    <Thumb.Template>
                        <ControlTemplate TargetType="Thumb">
                            <Canvas HorizontalAlignment="Center" VerticalAlignment="Top" Margin="-18,-38,18,0">
                                <Grid>
                                    <Ellipse Stroke="{ThemeResource AppBarItemForegroundThemeBrush}" Fill="{ThemeResource AppBarItemPressedForegroundThemeBrush}" StrokeThickness="2" Width="35" Height="35"/>
                                    <Path Fill="{ThemeResource AppBarItemForegroundThemeBrush}" Margin="0,0,0,-7" VerticalAlignment="Bottom" HorizontalAlignment="Center" Data="M 0,0 8,0 4,8Z"/>
                                </Grid>
                            </Canvas>
                        </ControlTemplate>
                    </Thumb.Template>
                </Thumb>
                <Canvas Visibility="{TemplateBinding ThumbnailVisibility}" IsHitTestVisible="False" Grid.Row="1" Grid.Column="1">
                    <ContentPresenter x:Name="ThumbnailContentPresenter" Content="{TemplateBinding ThumbnailContent}" Visibility="{TemplateBinding ThumbnailVisibility}"/>
                </Canvas>
            </Grid>

            <Rectangle x:Name="FocusVisualWhite" IsHitTestVisible="False" Stroke="{ThemeResource FocusVisualWhiteStrokeThemeBrush}" StrokeEndLineCap="Square" StrokeDashArray="1,1" Opacity="0" StrokeDashOffset="1.5" Margin="-5"/>
            <Rectangle x:Name="FocusVisualBlack" IsHitTestVisible="False" Stroke="{ThemeResource FocusVisualBlackStrokeThemeBrush}" StrokeEndLineCap="Square" StrokeDashArray="1,1" Opacity="0" StrokeDashOffset="0.5" Margin="-5"/>
        </Grid>
    </ControlTemplate>

    <Style TargetType="local:MediaPlayer">
        <Setter Property="InteractiveDeactivationMode" Value="All"/>
        <Setter Property="AutoHideBehavior" Value="All"/>
        <Setter Property="ControlPanelTemplate">
            <Setter.Value>
                <ControlTemplate TargetType="local:ControlPanel">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="MediaStates">
                                <VisualState x:Name="Opening"/>
                                <VisualState x:Name="Paused"/>
                                <VisualState x:Name="Playing"/>
                                <VisualState x:Name="Closed"/>
                                <VisualState x:Name="Buffering"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="LayoutStates">
                                <VisualState x:Name="Compact"/>
                                <VisualState x:Name="Normal"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="Orientation">
                                <VisualState x:Name="Landscape"/>
                                <VisualState x:Name="Portrait"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Border x:Name="Border" DataContext="{TemplateBinding ViewModel}">
                            <Border.Resources>
                                <local:BoolToVisibilityConverter x:Key="VisibleIfConverter" />
                            </Border.Resources>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>

                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
                                    <StackPanel Orientation="Horizontal" x:Name="NonEssentialsNearLeft">
                                        <AppBarButton x:Name="SkipPreviousButton" Width="70" Height="70" Margin="10,0,10,0" Style="{TemplateBinding PrimaryButtonStyle}" Visibility="{Binding IsSkipPreviousButtonVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}">
                                            <local:MediaControls.Behavior>
                                                <local:SkipPreviousButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            </local:MediaControls.Behavior>
                                        </AppBarButton>
                                        <AppBarButton x:Name="RewindButton" Width="70" Height="70" Margin="10,0,10,0" Style="{TemplateBinding PrimaryButtonStyle}" Visibility="{Binding IsRewindButtonVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}">
                                            <local:MediaControls.Behavior>
                                                <local:RewindButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            </local:MediaControls.Behavior>
                                        </AppBarButton>
                                        <AppBarButton x:Name="SkipBackButton" Width="70" Height="70" Margin="10,0,10,0" Style="{TemplateBinding PrimaryButtonStyle}" Visibility="{Binding IsSkipBackButtonVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}">
                                            <local:MediaControls.Behavior>
                                                <local:SkipBackButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            </local:MediaControls.Behavior>
                                        </AppBarButton>
                                    </StackPanel>

                                    <AppBarButton x:Name="PlayPauseButton" Margin="25,0,25,0" Width="140" Height="140" Style="{TemplateBinding PrimaryButtonStyle}" Visibility="{Binding IsPlayPauseButtonVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}">
                                        <local:MediaControls.Behavior>
                                            <local:PlayPauseButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}"/>
                                        </local:MediaControls.Behavior>
                                    </AppBarButton>

                                    <StackPanel Orientation="Horizontal" x:Name="NonEssentialsNearRight">
                                        <AppBarButton x:Name="SkipAheadButton" Width="70" Height="70" Margin="10,0,10,0" Style="{TemplateBinding PrimaryButtonStyle}" Visibility="{Binding IsSkipAheadButtonVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}">
                                            <local:MediaControls.Behavior>
                                                <local:SkipAheadButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            </local:MediaControls.Behavior>
                                        </AppBarButton>
                                        <AppBarButton x:Name="FastForwardButton" Width="70" Height="70" Margin="10,0,10,0" Style="{TemplateBinding PrimaryButtonStyle}" Visibility="{Binding IsFastForwardButtonVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}">
                                            <local:MediaControls.Behavior>
                                                <local:FastForwardButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            </local:MediaControls.Behavior>
                                        </AppBarButton>
                                        <AppBarButton x:Name="SkipNextButton" Width="70" Height="70" Margin="10,0,10,0" Style="{TemplateBinding PrimaryButtonStyle}" Visibility="{Binding IsSkipNextButtonVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}">
                                            <local:MediaControls.Behavior>
                                                <local:SkipNextButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            </local:MediaControls.Behavior>
                                        </AppBarButton>
                                    </StackPanel>
                                </StackPanel>

                                <Grid x:Name="TimelineContainer" Grid.Row="1" Background="{StaticResource TransportBackgroundBrush}">
                                    <Grid Margin="30,4,30,7">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <Button x:Name="TimeElapsedButton" Style="{TemplateBinding TransportBarTextButtonStyle}" Margin="8,0,8,0">
                                            <local:MediaControls.Behavior>
                                                <local:TimeElapsedButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            </local:MediaControls.Behavior>
                                        </Button>

                                        <local:Timeline Height="25" Padding="0,10,0,10" x:Name="Timeline" Grid.Column="1" SliderTemplate="{StaticResource SeekableSliderTemplate}" ViewModel="{TemplateBinding ViewModel}" Visibility="{Binding IsTimelineVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}" Margin="8,0,8,0" ThumbnailVisibility="{Binding IsThumbnailVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}">
                                            <local:Timeline.ThumbnailContent>
                                                <Border BorderThickness="2" BorderBrush="{ThemeResource ButtonForegroundThemeBrush}" Width="164" Height="94" Background="{ThemeResource ButtonPressedForegroundThemeBrush}" Margin="-76,-102,0,0">
                                                    <local:ThumbnailView ThumbnailImageSource="{Binding ThumbnailImageSource}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
                                                </Border>
                                            </local:Timeline.ThumbnailContent>
                                        </local:Timeline>

                                        <Button x:Name="TimeRemainingButton" Grid.Column="2" Style="{TemplateBinding TransportBarTextButtonStyle}" Visibility="{Binding IsTimeRemainingButtonVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}" Margin="8,0,8,0">
                                            <local:MediaControls.Behavior>
                                                <local:TimeRemainingButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            </local:MediaControls.Behavior>
                                        </Button>
                                        <Button x:Name="DurationButton" Grid.Column="2" Style="{TemplateBinding TransportBarTextButtonStyle}" Visibility="{Binding IsDurationButtonVisible, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource VisibleIfConverter}}" Margin="8,0,8,0">
                                            <local:MediaControls.Behavior>
                                                <local:DurationButtonBehavior ViewModel="{Binding ViewModel, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            </local:MediaControls.Behavior>
                                        </Button>
                                    </Grid>
                                </Grid>
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
